package com.castle.fortress.admin.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.castle.fortress.admin.member.dto.MemberSetingDto;
import com.castle.fortress.admin.member.entity.MemberSetingEntity;
import com.castle.fortress.admin.member.mapper.MemberSetingMapper;
import com.castle.fortress.admin.member.service.MemberSetingService;
import com.castle.fortress.common.utils.ConvertUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员设置表 服务实现类
 *
 * @author Mgg
 * @since 2021-11-26
 */
@Service
public class MemberSetingServiceImpl extends ServiceImpl<MemberSetingMapper, MemberSetingEntity> implements MemberSetingService {
    /**
    * 获取查询条件
    * @param memberSetingDto
    * @return
    */
    public QueryWrapper<MemberSetingEntity> getWrapper(MemberSetingDto memberSetingDto){
        QueryWrapper<MemberSetingEntity> wrapper= new QueryWrapper();
        if(memberSetingDto != null){
            MemberSetingEntity memberSetingEntity = ConvertUtil.transformObj(memberSetingDto,MemberSetingEntity.class);
        }
        return wrapper;
    }


    @Override
    public IPage<MemberSetingDto> pageMemberSeting(Page<MemberSetingDto> page, MemberSetingDto memberSetingDto) {
        QueryWrapper<MemberSetingEntity> wrapper = getWrapper(memberSetingDto);
        Page<MemberSetingEntity> pageEntity = new Page(page.getCurrent(), page.getSize());
        Page<MemberSetingEntity> memberSetingPage=baseMapper.selectPage(pageEntity,wrapper);
        Page<MemberSetingDto> pageDto = new Page(memberSetingPage.getCurrent(), memberSetingPage.getSize(),memberSetingPage.getTotal());
        pageDto.setRecords(ConvertUtil.transformObjList(memberSetingPage.getRecords(),MemberSetingDto.class));
        return pageDto;
    }


    @Override
    public List<MemberSetingDto> listMemberSeting(MemberSetingDto memberSetingDto){
        QueryWrapper<MemberSetingEntity> wrapper = getWrapper(memberSetingDto);
        List<MemberSetingEntity> list = baseMapper.selectList(wrapper);
        return ConvertUtil.transformObjList(list,MemberSetingDto.class);
    }
}

